<div class="content-body">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form" style="padding-bottom: 10px;">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">会员信息</label>
                        <div class="layui-input-inline">
                            <input type="text" name="keyword" placeholder="会员卡号/姓名/手机" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">变动类型</label>
                        <div class="layui-input-inline">
                            <select name="type">
                                <option value="">全部类型</option>
                                <option value="1">消费赠送</option>
                                <option value="2">签到赠送</option>
                                <option value="3">消费使用</option>
                                <option value="4">人工调整</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn" lay-submit lay-filter="LAY-points-search">
                            <i class="layui-icon layui-icon-search"></i>查询
                        </button>
                        <button class="layui-btn layui-btn-primary" lay-submit lay-filter="LAY-points-reset">重置</button>
                    </div>
                </div>
            </div>

            <!-- 工具栏 -->
            <div class="layui-btn-group" style="padding-bottom: 10px;">
                <button class="layui-btn" data-type="rule"><i class="layui-icon layui-icon-set"></i>积分规则</button>
            </div>

            <!-- 数据表格 -->
            <table id="LAY-points-list" lay-filter="LAY-points-list"></table>
        </div>
    </div>
</div>

<script>
layui.use(['table', 'form', 'layer'], function(){
    var $ = layui.$
    ,table = layui.table
    ,form = layui.form
    ,layer = layui.layer;
    
    //积分记录列表
    table.render({
        elem: '#LAY-points-list'
        ,url: '/app/ky_shouyin/admin/member/pointsList'
        ,cols: [[
            {field: 'id', title: 'ID', width: 80, sort: true}
            ,{field: 'member_name', title: '会员姓名', width: 100}
            ,{field: 'points', title: '积分变动', width: 100, templet: function(d){
                return d.points > 0 ? '<span style="color:#5FB878;">+'+d.points+'</span>' : '<span style="color:#FF5722;">'+d.points+'</span>';
            }}
            ,{field: 'type', title: '变动类型', width: 100, templet: function(d){
                var types = {1:'消费赠送', 2:'签到赠送', 3:'消费使用', 4:'人工调整'};
                return types[d.type] || '';
            }}
            ,{field: 'description', title: '变动说明'}
            ,{field: 'created_at', title: '变动时间', width: 160}
        ]]
        ,page: true
        ,limit: 15
        ,text: {
            none: '暂无数据'
        }
    });
    
    //监听搜索
    form.on('submit(LAY-points-search)', function(data){
        var field = data.field;
        
        //执行重载
        table.reload('LAY-points-list', {
            where: field
        });
    });
    
    //监听重置
    form.on('submit(LAY-points-reset)', function(data){
        //重置表单
        $('input[name="keyword"]').val('');
        $('select[name="type"]').val('');
        form.render('select');
        
        //重载表格
        table.reload('LAY-points-list', {
            where: {}
        });
    });

    var active = {
        rule: function(){
            location.href = '/app/ky_shouyin/admin/member/pointsRule';
        }
    };
    
    $('.layui-btn-group .layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
});
</script> 